class HotelRoomTypesController < ApplicationController
  # GET /hotel_room_types
  # GET /hotel_room_types.json
  def index
    if params[:hid]
      @hotel_room_types = HotelRoomType.where('hotel_id =?', params[:hid])

      respond_to do |format|
        format.js { render layout: false }
      end
    end
  end

  # GET /hotel_room_types/1
  # GET /hotel_room_types/1.json
  def show
    @hotel_room_type = HotelRoomType.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @hotel_room_type }
    end
  end

  # GET /hotel_room_types/new
  # GET /hotel_room_types/new.json
  def new
    @hotel_room_type = HotelRoomType.new

    respond_to do |format|
        format.js { render layout: false }
      end
  end

  # GET /hotel_room_types/1/edit
  def edit
    @hotel_room_type = HotelRoomType.find(params[:id])

    respond_to do |format|   
      format.js { render patial: false }    
    end
  end

  # POST /hotel_room_types
  # POST /hotel_room_types.json
  def create
    @hotel_room_type = HotelRoomType.new(params[:hotel_room_type])
    @hotel_room_type.save
    @hotel_room_types = HotelRoomType.where('hotel_id =?', @hotel_room_type.hotel_id)

    respond_to do |format|
      format.js { render patial: false }
    end
  end

  # PUT /hotel_room_types/1
  # PUT /hotel_room_types/1.json
  def update
    @hotel_room_type = HotelRoomType.find(params[:id])
    @hotel_room_type.update_attributes(params[:hotel_room_type])
    @hotel_room_types = HotelRoomType.where('hotel_id =?', @hotel_room_type.hotel_id)

    respond_to do |format|   
      format.js { render patial: false }    
    end
  end

  # DELETE /hotel_room_types/1
  # DELETE /hotel_room_types/1.json
  def destroy
    @hotel_room_type = HotelRoomType.find(params[:id])
    @delete_check = true if @hotel_room_type.destroy
    @hotel_room_types = HotelRoomType.where('hotel_id =?', params[:hid])

    respond_to do |format|   
      format.js { render patial: false }    
    end
  end

  def destroy_multiple
    Hotel.destroy(params[:hotels_ids])
    @hotels = Hotel.searching(hotel_search)
                         .order(sort_column + ' ' + sort_direction)
                         .paginate(:per_page => 10, :page => params[:page])

    respond_to do |format|
      flash[:notice] = "Selected hotel was successfully deleted."
      format.js { render layout: false }
      format.json { head :no_content }
    end
  end

  def room_facility_list
    @room_facilities = RoomFacility.all
    @hotel_id = params[:hotel_id]

    respond_to do |format|
      format.js { render layout: false }
    end
  end

  def room_facility_selected
    if params[:rti] and params[:room_facilities]
      RoomTypeFacility.where(:room_type_id => params[:rti]).destroy_all
      params[:room_facilities].each do |a|
        room_fac = RoomTypeFacility.new
        room_fac.room_type_id = params[:rti]
        room_fac.room_facility_id = a
        @saved = true  if room_fac.save
        @hotel_room_types = HotelRoomType.where('hotel_id =?', params[:hid])
      end
    end
    respond_to do |format|
      format.js { render layout: false }
    end
  end
end
